/*
Copyright (c) [2019年5月1日] [吴超]
[MBT_studio] is licensed under Mulan PSL v2.
You can use this software according to the terms and conditions of the Mulan PSL v2.
You may obtain a copy of Mulan PSL v2 at:
		 http://license.coscl.org.cn/MulanPSL2
THIS SOFTWARE IS PROVIDED ON AN "AS IS" BASIS, WITHOUT WARRANTIES OF ANY KIND,
EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO NON-INFRINGEMENT,
MERCHANTABILITY OR FIT FOR A PARTICULAR PURPOSE.
See the Mulan PSL v2 for more details.
*/
#pragma once

#include <节点/节点.h>
#include "节点/编译声明代码.h"
#include "节点/socket_utils.h"

#define DEF_VEC3_ALLOC_参数 bool 是否随机, int64 num, int32 随机种子, vec2 x, vec2 y, vec2 z
void* f_JIT_Fun_vec3_alloc(DEF_VEC3_ALLOC_参数);

#define DEF_vec3_随机_参数 int32 种子, const vec2& x, const vec2& y, const vec2& z
vec3 f_JIT_Fun_vec3_随机(DEF_vec3_随机_参数);
ivec3 f_JIT_Fun_ivec3_随机(int32 种子, const ivec2& x, const ivec2& y, const ivec2& z);

#define DEF_VEC3_SIZE_参数 const void* var
int64 f_JIT_Fun_vec3_size(DEF_VEC3_SIZE_参数);
vec3* f_JIT_Fun_vec3_data(DEF_VEC3_SIZE_参数);

S_Mat44Array* f_JIT_Fun_mat_构建矩阵(S_Vec3Array* 向量, S_F32Array* 角度, uint8 矩阵类型);
//S_Mat44Array* f_JIT_Fun_mat_构建移动矩阵(S_Vec3Array* 向量, S_F32Array* 角度);
//S_Mat44Array* f_JIT_Fun_mat_构建缩放矩阵(S_Vec3Array* 向量, S_F32Array* 角度);
//S_Mat44Array* f_JIT_Fun_mat_构建旋转矩阵(S_Vec3Array* 向量, S_F32Array* 角度);

void f_vec3_合并(S_Vec3Array* 向量, float32* x, float32* y, float32* z, uint32 size[3]);
void f_JIT_ivec3_合并(S_iVec3Array* 向量, S_I32Array* x, S_I32Array* y, S_I32Array* z);
void f_JIT_vec3_分离(S_F32Array* x, S_F32Array* y, S_F32Array* z, const S_Vec3Array* 向量);
void f_JIT_ivec3_分离(S_I32Array* x, S_I32Array* y, S_I32Array* z, const S_iVec3Array* 向量);

void f_JIT_重置I8数组(S_I8Array* 数组, uint32 num, int32 随机方式, ivec2 范围, int32 种子 = 0);
void f_JIT_创建F32数组(S_F32Array* a, uint32 num, int32 随机方式, vec2 范围, int32 种子 = 0);
void f_JIT_创建I32数组(S_I32Array* array, uint32 num, int32 随机方式, ivec2 范围, int32 种子 = 0);
void f_JIT_创建UI32数组(S_UI32Array* array, uint32 num, int32 随机方式, ivec2 范围, int32 种子 = 0);

void f_JIT_Fun_Vec3Clamp(S_Vec3Array* 向量, S_Vec3Array* 向量小, S_Vec3Array* 向量大, S_Vec3Array* 结果);




Inline std::string f_数组元素插座切换(C_节点基类* node, E_插座方向 方向, uint32 loc, E_值类型 数组类型) {
	std::string 类型;
	switch (数组类型) {
		case E_值类型::e_Type_I8_1D:
			f_su_切换后端插座类型(node, 方向, loc, E_值类型::e_Type_I8);
			类型 = DEF_S(int8)" ";
			break;
		case E_值类型::e_Type_F32_1D:
			f_su_切换后端插座类型(node, 方向, loc, E_值类型::e_Type_F32);
			类型 = DEF_S(float32)" ";
			break;
		case E_值类型::e_Type_I32_1D:
			f_su_切换后端插座类型(node, 方向, loc, E_值类型::e_Type_I32);
			类型 = DEF_S(int32)" ";
			break;
		case E_值类型::e_Type_Vec2_1D:
			f_su_切换后端插座类型(node, 方向, loc, E_值类型::e_Type_Vec2);
			类型 = DEF_S(vec2)" ";
			break;
		case E_值类型::e_Type_Vec3_1D:
			f_su_切换后端插座类型(node, 方向, loc, E_值类型::e_Type_Vec3);
			类型 = DEF_S(vec3)" ";
			break;
		case E_值类型::e_Type_Vec4_1D:
			f_su_切换后端插座类型(node, 方向, loc, E_值类型::e_Type_Vec4);
			类型 = DEF_S(vec4)" ";
			break;
		case E_值类型::e_Type_iVec3_1D:
			f_su_切换后端插座类型(node, 方向, loc, E_值类型::e_Type_iVec3);
			类型 = DEF_S(ivec3)" ";
			break;
		case E_值类型::e_Type_uVec2_1D:
			f_su_切换后端插座类型(node, 方向, loc, E_值类型::e_Type_uVec2);
			类型 = DEF_S(vec2)" ";
			break;
		case E_值类型::e_Type_多边形边1D:
			f_su_切换后端插座类型(node, 方向, loc, E_值类型::e_Type_多边形边);
			类型 = DEF_S(S_边*)" ";
			break;

		case E_值类型::e_Type_UI32_2D:
			f_su_切换后端插座类型(node, 方向, loc, E_值类型::e_Type_UI32_1D);
			类型 = DEF_S(S_UI32Array*)" ";
			break;
		//case E_值类型::e_Type_Array:
		//	break;
		default:
			std::cout << "error :" << node->f_getName() << "节点输入数据不是数组" << std::endl;
			return "";
	}
	return 类型;
}


void f_JIT_打乱数组(S_Array* 数组, int32 种子);
uint8* f_JIT_坐标取数组(S_Array* 数组, const ivec3& 坐标, const ivec3& 分辨率);

void f_JIT_3X3邻接数据(const S_Array* 数组, const ivec3& 坐标, const ivec3& 分辨率, S_Array* 邻接数据, S_I8Array* 空);


void f_node_所有变量类节点JIT初始化();



